package com.along.auth.controller;

import com.along.auth.dto.LoginDTO;
import com.along.auth.dto.RegisterDTO;
import com.along.auth.service.AuthService;
import com.along.utility.common.response.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/*
 *@Author: liujinyi
 *@CreateTime: 2025-08-05
 *@Description:
 *@Version: 1.0
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private AuthService authService;

    @PostMapping("/login")
    public GeneralResult<String> login(@Validated @RequestBody LoginDTO loginDTO, HttpServletRequest request) {
        String token = authService.login(loginDTO, request);
        return GeneralResult.success(token);
    }

    @PostMapping("/register")
    public GeneralResult<Void> register(@Validated @RequestBody RegisterDTO registerDTO) {
        authService.register(registerDTO);
        return GeneralResult.success();
    }
}
